/*
 * @Author: szx
 * @Date: 2022-02-26 14:34:35
 * @LastEditTime: 2022-02-26 14:39:48
 * @Description:
 * @FilePath: \leetcode\500-599\541\541_2.js
 */
/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
var reverseStr = function (s, k) {
    const arr = s.split('');
    for (let i = k; i < arr.length; i += 2 * k) {
        if (i >= arr.length) reverse(arr, i - k, arr.length - 1);
        else reverse(arr, i - k, k);
    }
    return s.join('');
};
const reverse = (arr, left, right) => {
    while (left < right) {
        const tmp = arr[left];
        arr[left] = arr[right];
        arr[right] = tmp;
    }
};
